@tool
class_name ContextBehavior_Arrive
extends BaseContextBehavior

#region 属性
@export var force:float
@export var target_reached_threshold:float = 0.5
## 实际的到达半径是否需要加上代理半径
@export var is_target_reached_threshold_add_body_radius:bool = true
@export var slow_radius:float = 2
## 实际的减速半径是否需要加上代理半径
@export var is_slow_radius_add_body_radius:bool = true
@export var target_pos:Vector2
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
func init():
	super()
func calc_steering(behaviors_owner:Node,agent:SteeringBehaviorAgent,delta:float):
	super(behaviors_owner,agent,delta)
	var to_target:Vector2 = target_pos - agent.get_pos()
	var distance = to_target.length()
	if distance < (target_reached_threshold if not is_target_reached_threshold_add_body_radius else target_reached_threshold + agent.body_radius):
		return
	else:
		var interest = to_target.normalized()* sensitive
		var real_slow_radius = slow_radius if not is_slow_radius_add_body_radius else slow_radius + agent.body_radius
		if distance <= real_slow_radius:
			interest *= distance / real_slow_radius
		agent.add_linear_force_interest(interest * force)
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _init() -> void:
	if Engine.is_editor_hint():
		resource_local_to_scene = true
	behavior_type = GameEnum.ContextBehaviorType.Arrive
func draw() -> void:
	super.draw()
	GameSteeringBehaviorDebug.draw_circle(target_pos - agent.get_pos(),target_reached_threshold if not is_target_reached_threshold_add_body_radius else target_reached_threshold + agent.body_radius,Color.RED,true)
	GameSteeringBehaviorDebug.draw_circle(agent.position,slow_radius,Color.GREEN,false,2)
#endregion
